﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace BibtexParser
{
	public class Bib
	{
		public string Id { get; set; }
		public string Type { get; set; }
		public IDictionary<string, string> Properties { get; private set; }

		public string Title
		{
			get
			{
				if (Properties.ContainsKey("title"))
					return Properties["title"];
				if (Properties.ContainsKey("Title"))
					return Properties["Title"];
				return null;
			}
		}

		public Bib()
		{
			Properties = new Dictionary<string, string>();
		}

		public override string ToString()
		{
			var propVals = string.Join("", Properties.Select(p => string.Format("\t{0}={{{1}}},\r\n", p.Key, p.Value)));
			const string rv = @"{0}{{{1},
{2}}}";
			return string.Format(rv, Type, Id, propVals);
		}
	}
}
